package com.xian.zk.common.properties;


import com.fasterxml.jackson.annotation.JsonIgnore;
import com.xian.zk.model.ServerNode;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: xian
 * @description:
 * @author: liru.xian
 * @create: 2020-08-14 15:26
 **/
@Data
@Configuration
@ConfigurationProperties(prefix = "x.zk")
public class ZookeeperProperties {
    public static final String symbol  = "/";

    @ApiModelProperty("实例ID")
    private String instanceId;
    /**
     * 服务名称
     */
    private String serverName;
    /**
     * 是否开启
     */
    private Boolean enabled;
    /**
     * 服务地址
     */
    private String address;
    /**
     * 注册根节点
     */
    private String registryPath;
    /**
     * 注册服务节点
     */
    private String serverPath;
    /**
     * sessionTimeout session 超时
     */
    private int sessionTimeoutMs;
    /**
     * connectionTimeout 连接超时
     */
    private int connectionTimeoutMs;
    /**
     * baseSleepTime 睡眠时间
     */
    private int baseSleepTimeMs;
    /**
     * maxRetries 最大重试次数
     */
    private int maxRetries;
    /**
     * 节点数据
     */
    private ServerNode node;

    @JsonIgnore
    public String getParentPath(){
        return symbol+this.getRegistryPath()+symbol+this.getServerName();
    }
}
